/**
**************************************************************************************
*Founder Effect                                                                      *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#pragma once

#include "../shared/vector.h"
#include "Typedefs.h"

template<class T>
class QuadTree;
class Scene;
class ICamera;
class IEntity;


/**
===========================
Handles all collisions between
terrain and entities
===========================
*/
class CollisionManager
{
public:
    CollisionManager(void);
    /** Update each entity */
    void Update( ICamera* camera, Scene* scene, type_EntityMap &entities, float deltaTime );

    /** Set the QuadTree */
    void SetQuadTree( QuadTree<IEntity*> *q ) { m_entityQuadTree = q; };

private:
    /** Move each entity that needs to be moved */
    bool Move(IEntity* ent, ICamera* cam, Scene* scene, float deltaTime);

    /** Move X coord of an ent */
    float MoveX(IEntity *ent, float xmove, Vector2f &oldPosition, Scene* scene );
    /** Move Y coord of an ent */
    float MoveY(IEntity *ent, float ymove, Vector2f &oldPosition, Scene* scene );

    /** Check collision between entities */
    bool CheckCollision(IEntity* ent, const Vector2f &pos );
    /** Apply Gravity */
    bool CheckGravity(IEntity* ent, float deltaTime);
    /** Check type of motion */
    Vector2f GetMotion(IEntity* ent);

    // quick list to all entities in the world
    QuadTree<IEntity*> *m_entityQuadTree;
public:
    virtual ~CollisionManager(void);
};
